package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-02-24
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Resource
    private EduTeacherMapper eduTeacherMapper;
    @Resource
    private EduCourseService eduCourseService;

    @Override
    public Long getNextSort() {
        return eduTeacherMapper.getNextSort().get("sort");
    }

    @Override
    public Map<String, Object> getTeacherInfo(String id) {
        EduTeacher teacher = super.lambdaQuery().eq(EduTeacher::getId, id).select(EduTeacher::getId, EduTeacher::getName,
                EduTeacher::getAvatar, EduTeacher::getLevel, EduTeacher::getIntro, EduTeacher::getCareer).one();
        List<EduCourse> courses = eduCourseService.lambdaQuery().eq(EduCourse::getTeacherId, id)
                .eq(EduCourse::getStatus,"Normal")
                .select(EduCourse::getTitle, EduCourse::getId,
                EduCourse::getCover).list();
        Map<String, Object> result = Maps.newHashMap();
        result.put("teacher", teacher);
        result.put("courses", courses);
        return result;
    }
}
